package soar.test.nlp;

import java.util.List;
import java.util.stream.Collectors;

import org.ansj.splitWord.analysis.ToAnalysis;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.dictionary.py.Pinyin;
import com.hankcs.hanlp.seg.common.Term;

public class App
{
    public static void main(String[] args)
    {
        new App().run();
    }

    private void run()
    {
        try
        {
            String split = "========================================";

            System.out.println(split);

            test_hanlp();
            System.out.println(split);
        }
        catch (Exception e)
        {
            System.err.println(e);
        }
    }

    private void test_hanlp()
    {
        String split = "----------------------------------------";
        for (String text : new String[] { "你好，欢迎使用HanLP汉语处理包！", "拜仁慕尼黑",
                "拜仁木尼黑", "常山赵子龙", "华山栈道", "华山栈刀", "C罗 J罗", "火箭哈登",
                "詹皇 勒布朗 勒布朗詹姆斯", "中国模仿帝", "吴亦凡 吴一凡", "diss", "实战利器",
                "小牛 小牛队 小牛詹姆斯 小牛独行侠", "王者荣耀 英雄联盟", "路人王", "基督教徒",
                "火箭赢了送5000人民币","领巾 红领巾" })
        {
            List<Term> terms = HanLP.segment(text);
            System.out.println(text);
            System.out.println();
            terms.forEach(term -> {
                System.out.println(String.format("%s", term.word));
            });
            System.out.println(split);

            for (int i = 0; i < text.length(); i++)
            {
                String s = text.substring(i, i + 1);
                char ch = s.toCharArray()[0];
                if (0x4e00 <= ch && ch <= 0x9fa5)
                {
                    System.out.print(HanLP.convertToPinyinList(s).stream()
                            .map(p -> p.getPinyinWithoutTone())
                            .collect(Collectors.joining()));
                }
                else
                {
                    System.out.print(s);
                }
            }
            System.out.println();
            System.out.println(split);
        }
    }
}